package com.sbr.seb.wicket.page.administration;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.spring.injection.annot.SpringBean;

import com.sbr.seb.entity.composants.Category;
import com.sbr.seb.planning.dao.CategoryDao;

public class AdminCategoriesPage extends AdministrationBasePage {

	@SpringBean
	private CategoryDao categoryDao;
	
    public AdminCategoriesPage() {
    	super();
    	
    	add(new ListView<Category>("categoriesList", categoryDao.findAll()) {

			@Override
			protected void populateItem(ListItem<Category> item) {
				Category category = item.getModelObject();
				item.add(new Label("categoryName", category.getName()));
				item.add(new Label("categoryDescription", category.getDescription()));
				if (category.getUpperCategory() != null) {
					item.add(new Label("category", category.getUpperCategory().getName()));
				} else {
					item.add(new Label("category", ""));
				}
			}
    		
    	});
    	
    	add(new BookmarkablePageLink("addCategoryLink", AddCategoryPage.class));
    	
    }

	public void setCategoryDao(CategoryDao categoryDao) {
		this.categoryDao = categoryDao;
	}

}
